<template>
  <div>
    <el-form
      ref="addRuleFormRef"
      :inline="true"
      :model="addRuleForm"
      :rules="addRules"
      class="demo-form-inline"
      label-position="right"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="登录错误次数" prop="error_count">
            <el-input
              v-model="addRuleForm.error_count"
              placeholder="达到错误次数后锁定用户"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="登录错误时间" prop="error_date">
            <el-input
              v-model="addRuleForm.error_date"
              placeholder="(分钟)。超过时间重计次数"
              clearable
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="button_row">
        <el-col :span="24">
          <el-form-item>
            <el-button type="primary" @click="submitForm(addRuleFormRef)">
              确定
            </el-button>
            <el-button @click="onReset(addRuleFormRef)">取消</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script  setup>
import { ref, reactive } from 'vue'

const addRuleFormRef = ref()
const addRuleForm = ref({
  error_count: '',
  error_date: ''
})
// 校验规则
const addRules = reactive({
  error_count: [{ required: true, message: '请输入错误次数', trigger: 'blur' }],
  error_date: [
    { required: true, message: '请输入登录错误时间', trigger: 'blur' }
  ]
})

// // 提交
const submitForm = async (formEl) => {
  console.log(formEl)
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log(addRuleForm)
    } else {
      console.log('error submit!', fields)
    }
  })
}
// // 重置
const onReset = (formEl) => {
  addRuleForm.value = {
    error_count: '',
    error_date: ''
  }
  formEl.resetFields()
}
// const handleSelectionChange = (selection) => {
//     ids.value = selection.map(item => item.date)
//     multiple.value = !selection.length
// }
</script>

<style lang="scss" scoped>
.button_row {
  text-align: center;
  margin-top: 30px;
}
</style>
